const jwt = require('jsonwebtoken');
const secret = require('../config/secret');
class Token {
    // 生成token
    createToken(user, id = '', expires, strTimer, roles) {
        let token;
        /**判断用户系统 */
        if (roles === 'admin') {
            token = jwt.sign({User: user, role: { role: id }}, secret.admin, {expiresIn: expires + ' ' + strTimer});
        } else {
            token = jwt.sign({User: user, role: { role: id }}, secret.program, {expiresIn: expires + ' ' + strTimer});
        }
        return token;
    }
}
module.exports = new Token();
